#include <stdio.h>
#include <stdlib.h>

int cmp(const void* a, const void* b) 
{
    long long aa = *(long long*)a;
    long long bb = *(long long*)b;
    if (aa < bb) return -1;
    if (aa > bb) return 1;
    return 0;
}

int main() 
{
    int n;
    scanf_s("%d", &n);
    long long* a = (long long*)malloc(n * sizeof(long long));
    int has_zero = 0;
    for (int i = 0; i < n; i++) {
        scanf_s("%lld", &a[i]);
        if (a[i] == 0) 
        {
            has_zero = 1;
        }
    }

    int all_zero = 1;
    for (int i = 0; i < n; i++) 
    {
        if (a[i] != 0)
        {
            all_zero = 0;
            break;
        }
    }
    if (all_zero)
    {
        printf("0\n");
        free(a);
        return 0;
    }

    if (!has_zero) 
    {
        int all_same = 1;
        for (int i = 1; i < n; i++) 
        {
            if (a[i] != a[0]) 
            {
                all_same = 0;
                break;
            }
        }
        if (all_same) 
        {
            printf("0\n");
        }
        else 
        {
            printf("-1\n");
        }
        free(a);
        return 0;
    }

    qsort(a, n, sizeof(long long), cmp);
    int j = 0;
    for (int i = 1; i < n; i++)
    {
        if (a[i] != a[j]) 
        {
            j++;
            a[j] = a[i];
        }
    }
    int distinct_size = j + 1;
    long long M = a[distinct_size - 1];

    long long* gaps_start = (long long*)malloc((distinct_size + 1) * sizeof(long long));
    long long* gaps_end = (long long*)malloc((distinct_size + 1) * sizeof(long long));
    int gap_count = 0;

    for (int i = 0; i < distinct_size - 1; i++)
    {
        if (a[i] + 1 < a[i + 1])
        {
            gaps_start[gap_count] = a[i] + 1;
            gaps_end[gap_count] = a[i + 1] - 1;
            gap_count++;
        }
    }
    gaps_start[gap_count] = a[distinct_size - 1] + 1;
    gaps_end[gap_count] = -1; 
    gap_count++;

    long long S = 0;
    long long rounds = 0;

    while (S < M)
    {
        long long x = S + 1;
        int found_index = -1;
        int low = 0, high = gap_count - 1;
        while (low <= high)
        {
            int mid = (low + high) / 2;
            if (gaps_start[mid] <= x) 
            {
                found_index = mid;
                low = mid + 1;
            }
            else
            {
                high = mid - 1;
            }
        }

        if (found_index != -1) 
        {
            if (gaps_end[found_index] == -1)
            {
            }
            else if (gaps_end[found_index] >= x) 
            {
            }
            else 
            {
                if (found_index + 1 < gap_count)
                {
                    x = gaps_start[found_index + 1];
                }
            }
        }
        else 
        {
            if (gap_count > 0)
            {
                x = gaps_start[0];
            }
        }

        long long c = x - S;
        rounds++;
        S += c;
    }
    printf("%lld\n", rounds);
    free(a);
    free(gaps_start);
    free(gaps_end);
    return 0;
}